package com.bsh.erp.pro.warehouse.action;

import com.alibaba.fastjson.JSON;
import com.bsh.erp.base.BaseAction;
import com.bsh.erp.entity.InBill;
import com.bsh.erp.entity.OutBill;
import com.bsh.erp.tools.HqlHelper;
import com.bsh.erp.tools.PageBean;

/**
 * 出库单
 * @author JiaQi
 *
 */
public class OutBillAction extends BaseAction<OutBill>{
	/**
	 * 新增出库单
	 */
	public void addOutBill(){
		try{
			outBillService.save(getModel());
			outJson("成功！");
		}catch (Exception e) {
			outJson("失败！");
		}
	}
	
	/**
	 * jia
	 * 修改出库单
	 */
	public void updateInBill(){
		try{
			outBillService.update(getModel());
			outJson("成功！");
		}catch (Exception e) {
			outJson("失败!");
		}
	}
	
	/**
	 * 获取全部出库单
	 * 分页 10行
	 * pageNum 页码
	 * @return JSON数据
	 */
	public void findAllOutBill(){
		HqlHelper hqlHelper = new HqlHelper(OutBill.class, "outbill");
		PageBean pageBean = outBillService.getPageBean(pageNum, 10, hqlHelper);
		outJson(JSON.toJSONString(pageBean));
	}
	
	/**
	 * 获取未审核 未审核
	 * examined Y N 审核
	 * pageNum 页码
	 * @author JiaQi
	 * @return JSON
	 */
	public void findUnOutBill(){
		HqlHelper hqlHelper = new HqlHelper(OutBill.class, "outbill").addWhereCondition("examined = ?", getModel().getExamined());
		PageBean pageBean = outBillService.getPageBean(pageNum, 10, hqlHelper);
		outJson(JSON.toJSONString(pageBean));
	}
	
	/**
	 * 反审核 审核出库单
	 * examined  Y N  审核 反审核
	 * id 数据id
	 * @author JiaQi
	 * @return Y N
	 */
	public void toExaminedOutBill(){
		if(outBillService.examinedEntity(getModel().getId(),getModel().getExamined())){
			outJson("成功！");
		}else{
			outJson("失败！");
		}
	}
	
	/**
	 * 作废 反作废 出库单
	 * enable 作废 反作废 
	 * id  执行数据的id
	 * @author JiaQi
	 * @return Y N
	 */
	public void toEnableOutBill(){
		if(outBillService.cancelEntity(getModel().getId(),getModel().getEnabled())){
			outJson("成功！");
		}else{
			outJson("失败！");
		}
	}
	
	/**
	 * 获取为作废出库单
	 * enable  Y N 作废 反作废
	 * pageNum  页码
	 * @author JiaQi
	 * @return JSON
	 */
	public void UnEnableOutBill(){
		HqlHelper hqlHelper = new HqlHelper(OutBill.class, "outbill").addWhereCondition("enable = ?", getModel().getEnabled());
		PageBean pageBean = outBillService.getPageBean(pageNum, 10, hqlHelper);
		outJson(JSON.toJSONString(pageBean));
	}
}
